package tributos.util;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

import tributos.modelo.Cidades;
import tributos.modelo.Contato;
import tributos.modelo.Contribuinte;
import tributos.modelo.Endereco;
import tributos.modelo.Imoveis;
import tributos.modelo.Imposto;

public class HibernateUtil {

	private static SessionFactory factory;  
	  
    static {  
        Configuration cfg = new Configuration();
        cfg.configure("hibernate.cfg.xml");
        cfg.addAnnotatedClass(Contribuinte.class);
        cfg.addAnnotatedClass(Endereco.class);
        cfg.addAnnotatedClass(Imoveis.class);
        cfg.addAnnotatedClass(Contato.class);
        cfg.addAnnotatedClass(Cidades.class);
        cfg.addAnnotatedClass(Imposto.class);
        ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();  
        factory = cfg.buildSessionFactory(serviceRegistry);  
  
    }  
      
    public static Session getSession() {  
        return factory.openSession();  
    }  

}
